package mysqltesting

import (
	"data-transfer/conf"
	"data-transfer/core"
	"data-transfer/global"
	"data-transfer/plugins"
	mm "data-transfer/plugins/mysql"
	"data-transfer/source"
	"testing"
)

const (
	configPath = "transfer.toml"
)

var dbconf *conf.DbConfig

func RunWithMysql(m *testing.M) int {
	mm.InitPlugin()

	global.GViper = core.Viper(configPath) // 初始化Viper
	global.LOG = core.Zap()                //初始化zap log

	//1.创建Mysql数据源
	var mysqlDataSource = new(source.MysqlSource)
	dbconf = mysqlDataSource.Config()
	return m.Run()
}

func NewTargetStore() (plugins.DB, error) {
	return plugins.NewSQLDB(plugins.DbKindTarget, dbconf)
}

func NewSourceStore() (plugins.DB, error) {
	return plugins.NewSQLDB(plugins.DbKindSource, dbconf)
}

func NewCanalStore() (plugins.DB, error) {
	return plugins.NewSQLDB(plugins.DbKindCanal, dbconf)
}

func NewInfoServiceStore() (plugins.DB, error) {
	return plugins.NewSQLDB(plugins.DbKindCanal, dbconf)
}
